import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import routes from './routers/main_router'
import axios from 'axios'

import { Tabbar, TabbarItem, Button, Col, Row, 
         Tab, Tabs , Search, Cell, CellGroup , Icon , 
         NavBar , Image as VanImage , Lazyload , Sticky , Skeleton , Loading , DropdownMenu, DropdownItem , 
         Rate , Popup , TreeSelect , Divider , Grid , GridItem , 
         DatetimePicker , ActionSheet , AddressEdit ,  AddressList , Empty , Card , RadioGroup ,
         Radio , Picker , Uploader , Toast , Field , ShareSheet , CouponCell , CouponList , 
         Badge , Stepper , Dialog , Checkbox, CheckboxGroup} from 'vant';

Vue.use(Lazyload, {
  lazyComponent: true,
});


Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Badge);
Vue.use(Stepper);
Vue.use(Dialog);
Vue.use(CouponCell);
Vue.use(CouponList);
Vue.use(ShareSheet);
Vue.use(Picker);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(Uploader);
Vue.use(Toast);
Vue.use(Field);
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(Divider);
Vue.use(TreeSelect);
Vue.use(Popup);
Vue.use(Rate);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Loading);
Vue.use(Skeleton);
Vue.use(Sticky);
Vue.use(Lazyload);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(ActionSheet);
Vue.use(AddressEdit);
Vue.use(AddressList);
Vue.use(VanImage);
Vue.use(Empty);
Vue.use(Card);
Vue.use(NavBar);
Vue.use(Icon);
Vue.use(Cell);
Vue.use(CellGroup)
Vue.use(Search);
Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Col);
Vue.use(Row);
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(Button);
Vue.use(VueRouter);
Vue.config.productionTip = false

Vue.prototype.axios = axios
axios.defaults.baseURL = "http://localhost:3000/"
// import { Toast } from 'vant'

Vue.prototype.$EventBus = new Vue();

const router = new VueRouter({
  routes:routes.routes
})
router.beforeEach((to, from, next) => {
  const waimai = localStorage.getItem('waimai');
  if (waimai){
    next()
  }else{
    if(to.path == '/takeout' || to.path == '/user' || to.path == '/login' || to.path == '/vip_unlogin' || to.path == '/order_unlogin'){
      next()
    }else{
      Toast.fail('请先登陆')
       next({path: "/login"})
    }
  }
})


new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
